<!--
 * @Author: your name
 * @Date: 2022-04-18 17:41:17
 * @LastEditTime: 2022-06-17 17:43:40
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \macc.admin.vue\src\views\system\usercenter\wxcallback.vue
-->
<template>
  <div></div>
</template>
<script>
import { maccApi, requestHttp } from '@utils/index';
export default {
  mounted() {
    const code = this.$route.query?.code || '';
    const type = this.$route.query?.type || '';
    console.log(this.$route, 'code', code);

    if (type == 'UNBIND') {
      this.unbinWX(code);
    } else {
      this.binWX(code);
    }
  },
  methods: {
    async binWX(wxcode) {
      const url = `${maccApi.TENANT_WXBINACCOUNT_PUT_API}?code=${wxcode}`;
      const { code } = await requestHttp({
        api: url,
        method: 'PUT',
        params: {},
      });
      if (code == 0) {
        window.opener.vm_maccadmin.$message.success('微信绑定成功');
        window.opener.location.reload();
      } else {
        window.opener.vm_maccadmin.$message.error('微信绑定失败');
      }

      window.close();
    },
    async unbinWX(wxcode) {
      const url = `${maccApi.TENANT_WXUNBINACCOUNT_PUT_API}?code=${wxcode}`;
      const { code } = await requestHttp({
        api: url,
        method: 'PUT',
        params: {},
      });
      if (code == 0) {
        window.opener.vm_maccadmin.$message.success('微信解绑成功');
        window.opener.location.reload();
      } else {
        window.opener.vm_maccadmin.$message.error('微信解绑失败');
      }

      window.close();
    },
  },
};
</script>
